<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>
        <ui:composition>
            <h:form >
                <p:growl id="growl" showDetail="true" life="3000" />  
                <p:dialog id="dialog" widgetVar="dlgLogin" modal="true">  
                    <h:panelGrid columns="1">  
                        <h1 class="sign-up-title">Sign in with us</h1>                         
                        <p:inputText value="#{loginController.username}"   styleClass="sign-up-input"
                                     id="username" required="true" label="username" 
                                     />  
                        <p:watermark for="username" value="Enter Username" />                          
                        <h:inputSecret value="#{loginController.password}"  styleClass="sign-up-input" 
                                       id="password" required="true" label="password"
                                       />  
                        <p:watermark for="password" value="Enter Password" />
                        <p:commandButton id="loginButton" value="Login"  styleClass="sign-up-button"
                                         actionListener="#{loginController.checkUserLogin}"  
                                         oncomplete="handleLoginRequest(xhr, status, args)"
                                         />  
                        <br/>
                        <a href="#{request.contextPath}/faces/Client/Register.xhtml">Don't have any account - Sign Up</a>
                        <a href="Register-forgot.html">Forgot your password?</a>
                    </h:panelGrid>  


                </p:dialog>  
            </h:form>
            <script type="text/javascript">
                function handleLoginRequest(xhr, status, args) {
                    if (args.validationFailed || !args.loggedIn) {
                        jQuery('#dialog').effect("shake", {times: 3}, 100);
                    } else {
                        dlgLogin.hide();
                        location.reload();
                        jQuery('#loginLink').fadeOut();
                    }

                }

                function handleRegisterRequest() {

                    dlgLogin.hide();
                }
            </script> 
        </ui:composition>

    </body>
</html>
